<template>
	<view class="app">
		<view class="search-div"><u-search @custom="searchList" placeholder="请输入商户名" v-model="params.merchant_name" @search="searchList"></u-search></view>
		<u-gap height="120rpx"></u-gap>
		<view class="">
			<u-list @scrolltolower="scrolltolower" height="calc(100vh - 200rpx)">
				<u-list-item v-for="(item, index) in List" :key="index">
					<view class="u-p-32 content-box">
						<view class=" u-flex">
							<view class="u-flex-3">
								<view class="u-m-b-20">
									<text>商户名:</text>
									<text>{{ item.merchant_name }}</text>
								</view>
								<view class="u-m-b-20">
									<text>申请金额:</text>
									<text>￥{{ item.withdraw }}(手续费:￥{{ item.service_charge }})</text>
								</view>
								<view class="u-m-b-20">
									<text>提现账号:</text>

									<text v-if="item.is_online == 1">{{ item.type == 1 ? '微信零钱' : '用户余额' }}</text>
									<template v-else>
										<text>{{ item.card ? item.card.name : '' }}:</text>
										<text>{{ item.card ? item.card.card : '' }}</text>
									</template>
								</view>

								<view>
									<text>状态:</text>
									<text>{{ item.status_text }}</text>
								</view>
							</view>
						</view>
						<u-line margin="20rpx 0" v-if="item.status == 0"></u-line>
						<view class="btn u-flex" v-if="item.status == 0">
							<u-button shape="circle" customStyle="width:160rpx;margin:0 10rpx" size="small" type="primary" @click="operateItem(index, 1)">打款通过</u-button>
							<u-button shape="circle" customStyle="width:160rpx;margin:0 10rpx" size="small" type="primary" @click="operateItem(index, 2)">拒绝</u-button>
						</view>
					</view>
				</u-list-item>
				<u-loadmore @loadmore="getDataList" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
			</u-list>
		</view>
		<u-modal :show="show_model" @cancel="show_model = false" :showCancelButton="true" :content="content" @confirm="confirm"></u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
export default {
	data() {
		return {
			params: {
				merchant_name: ''
			},
			page: 1,
			size: 10,
			objTemp: {},
			isLoading: false,
			List: [],
			status: 'loadmore',
			loadingText: '努力加载中',
			loadmoreText: '上拉或点击加载更多',
			nomoreText: '实在没有了',
			show_model: false,
			btn_type: -1,
			detail: '',
			content: ''
		};
	},

	mounted() {
		this.searchList();
	},
	methods: {
		changelist() {
			let id = this.List[this.index].id;
			uni.$u.http
				.get('/madmin/merchant/withdraw/' + id, {custom:{id:18}})
				.then(res => {
					let detail = res.msg;

					this.List[this.index].status = detail.status;
					this.List[this.index] = detail;

					// this.List[i].order_type = detail.order_type;
				})
				.catch(err => {});
		},
		confirm() {
			let item = this.List[this.index];
			let data = {
				id: item.id,
				update_time: item.update_time
			};
			if (this.btn_type == 1) {
				data.status = 1;
			} else {
				data.status = 2;
			}

			uni.$u.http
				.put('/madmin/merchant/withdraw/' + data.id, data,{custom:{id:18}})
				.then(res => {
					this.show_model = false;
					this.changelist();
					this.$refs.uToast.show({
						message: '操作成功',
						type: 'success',
						complete: () => {}
					});
				})
				.catch(err => {
					console.log(uni.$u.toast);
				});
		},
		operateItem(index, type) {
			this.index = index;
			this.btn_type = type;
			this.content = type == 1 ? '是否打款通过？' : '是否拒绝申请？';
			this.show_model = true;
		},
		scrolltolower() {
			this.getDataList();
		},

		//查询数据
		searchList() {
			//复制查询对象
			this.objTemp = {...this.params};
			this.List = [];

			this.getDataList();
		},
		//查询数据本体
		getDataList() {
			this.isLoading = true;
			uni.$u.http
				.post('/madmin/merchant/withdraw/list?page=' + this.page + '&size=10', this.objTemp,{custom:{id:18}})
				.then(res => {
					this.isLoading = false;
					uni.stopPullDownRefresh();
					let json = res.msg;
					if (json.data.length > 0) {
						this.page++;
						let list = json.data;

						this.List = this.List.concat(list);
					} else {
						this.status = 'nomore';
					}
				})
				.catch(e => {
					this.isLoading = false;
				});
		}
	}
};
</script>
<style lang="scss">
.content-box {
	margin: 20rpx auto;
	position: relative;
	font-size: 28rpx;
}
.search-box {
	width: 520rpx;
}
.tabs-div {
	top: 0;
}
</style>
